<a href="javascript:storeSel.load();" class="btn btn-mini btn-return">&plus;选择店铺</a>
<input type="hidden" name="{$param.name}" id="J_stores_input" value="{$param.value}">
<span class="user-sum J_stores_tip"></span>
<script>
var storeSel = {
  index : '{:addons_url("StoreSel://StoreSel/index?type=".$param["type"])}',
  load: function(){
    UI.load(this.index , '选择店铺');
  },
  manage: function(){
    var stores = $('input[name="{$param.name}"]').val();
    var url = this.index;
    //console.log(stores);
    if(stores === ''){
      $('.modal-title').text('选择店铺');
    }
    url = url + (url.indexOf('?') > -1 ? '&' : '?') + 'stores=' + stores;
    UI.load(url, '已选择店铺');
  },
  search: function(param){
    var url = this.index;
    url = url + (url.indexOf('?') > -1 ? '&' : '?') + param;
    UI.load(url);
  },
  selSum: function(){
    var storesel = $('#J_stores_input').val(),
        tip_text = '',
        tip_obj = $('.J_stores_tip');
    if('{$param.type}' == 'radio'){
      //console.log(stores);
      if(stores > 0){
        //单选
        tip_obj.html('...');
        url = '{:addons_url("StoreSel://StoreSel/getUserInfo")}';
        $.get(url, {uid: stores}, function(data){
          html = '<span class="show-userinfo">'+ (data.avatar != '' ? '<img src="'+ data.avatar +'" width="32">': '') + data.nickname + (data.mobile != '' ? '（'+ data.mobile +'）' : '') + '</span>';
          html+= '<a href="javascript:storeSel.load();" class="btn btn-default">重新选择</a>';
          tip_obj.html(html);
        }, 'json');
      }else{
        tip_text = '<a href="javascript:storeSel.load();" class="btn btn-mini btn-return">选择店铺</a>';
      }
    }else{
      //复选框
      sum = storesel === '' ? 0 : storesel.split(',').length;
      tip_text = '已选择 <strong class="text-danger">'+ sum +'</strong> 个店铺 (<a href="javascript:storeSel.manage();">管理</a>)';
      if(sum === 0){
        tip_text = "<empty name='param.empty_tip'>尚未选择店铺<else/>{$param.empty_tip}</empty>";
      }
    }
    tip_obj.html(tip_text);
  }
};
//统计选择店铺数量
$(function(){
  storeSel.selSum();
});
</script>